<template>
    <div>
        <van-nav-bar title="我的订单" left-text="返回" left-arrow @click-left="$router.push('/user')" />
        <van-tabs v-model="active" sticky @click="onClick">
            <van-tab title="全部">
                <van-skeleton title :row="15" :loading="loading" />
                <AllOrder :orderList="orderList" v-show="!loading" @refreshData="refreshData"></AllOrder>
            </van-tab>
            <van-tab title="待付款">
                <van-skeleton title :row="15" :loading="loading" />
                <Obligation :orderList="orderList" v-show="!loading" @refreshData="refreshData"></Obligation>
            </van-tab>
            <van-tab title="待服务">
                <van-skeleton title :row="15" :loading="loading" />
                <WaitService :orderList="orderList" v-show="!loading" @refreshData="refreshData"></WaitService>
            </van-tab>
            <van-tab title="服务中">
                <van-skeleton title :row="15" :loading="loading" />
                <Serviceing :orderList="orderList" v-show="!loading" @refreshData="refreshData"></Serviceing>
            </van-tab>
            <van-tab title="待评价">
                <van-skeleton title :row="15" :loading="loading" />
                <WaitFeedback :orderList="orderList" v-show="!loading" @refreshData="refreshData"></WaitFeedback>
            </van-tab>
        </van-tabs>
    </div>
</template>

<script>
import AllOrder from './AllOrder'
import Obligation from './Obligation'
import WaitService from './WaitService'
import Serviceing from './Serviceing'
import WaitFeedback from './WaitFeedback'
export default {
    name: "Order",
    components: {
        AllOrder,
        Obligation,
        WaitService,
        Serviceing,
        WaitFeedback
    },
    mounted() {
        this.init()
    },
    data() {
        return {
            // 默认标签
            active: this.$route.query.tag != undefined ? parseInt(this.$route.query.tag) : 0,
            // 订单列表
            orderList: [],
            // 当前页数
            currentPag: 1,
            // 每页大小
            pageSize: 10,
            // 总页数
            totalPag: 0,
            //是否加载
            loading: true
        }
    },
    methods: {
        // 初始化
        init() {
            let tagActive = this.$route.query.tag != undefined ? this.$route.query.tag : 0
            let returnMethod = this.$route.query.method
            if (returnMethod == 'alipay.trade.wap.pay.return') {
                this.$toast.success('支付成功')
            }
            this.judgeActive(tagActive)
        },
        // 切换tab
        onClick(name, title) {
            // 重置当前页数
            this.currentPag = 1
            this.judgeActive(name)
        },
        // 判断当前标签
        judgeActive(name) {
            if (name == 0) this.getAll()
            else if (name == 1) this.getObligation()
            else if (name == 2) this.getWaitService()
            else if (name == 3) this.getServiceing()
            else if (name == 4) this.getWaitFeedback()
        },
        // 全部
        async getAll() {
            this.loading = true
            let res = await this.$store.dispatch('getOrderList', {
                currentPag: this.currentPag,
                pageSize: this.pageSize
            })
            this.loading = false
            if (res.success) this.orderList = res.data.orderList, this.totalPag = res.data.totalPag
            else this.$myFun.resError(res.message)
        },
        // 未付款
        async getObligation() {
            this.loading = true
            let res = await this.$store.dispatch('getOrderList', {
                currentPag: this.currentPag,
                pageSize: this.pageSize,
                isPayment: 2
            })
            this.loading = false
            if (res.success) this.orderList = res.data.orderList, this.totalPag = res.data.totalPag
            else this.$myFun.resError(res.message)
        },
        // 待服务
        async getWaitService(){
            this.loading = true
            let res = await this.$store.dispatch('getOrderList', {
                currentPag: this.currentPag,
                pageSize: this.pageSize,
                isPayment: 1,
                isDeal: 2
            })
            this.loading = false
            if (res.success) this.orderList = res.data.orderList, this.totalPag = res.data.totalPag
            else this.$myFun.resError(res.message)
        },
        // 服务中
        async getServiceing(){
            this.loading = true
            let res = await this.$store.dispatch('getOrderList', {
                currentPag: this.currentPag,
                pageSize: this.pageSize,
                isPayment: 1,
                isDeal: 1
            })
            this.loading = false
            if (res.success) this.orderList = res.data.orderList, this.totalPag = res.data.totalPag
            else this.$myFun.resError(res.message)
        },
        // 待评价
        async getWaitFeedback(){
            this.loading = true
            let res = await this.$store.dispatch('getOrderList', {
                currentPag: this.currentPag,
                pageSize: this.pageSize,
                isPayment: 1,
                isDeal: 1,
                isFeedback: 2
            })
            this.loading = false
            if (res.success) this.orderList = res.data.orderList, this.totalPag = res.data.totalPag
            else this.$myFun.resError(res.message)
        },
        // 重新刷新
        refreshData(){
            this.init()
        }
    },


}
</script>

<style scoped></style>